include("shared.lua")

local Chat = {
	Tree1 = { "Got any guns for sale?", function() ChatFrame:SetVisible( false ) DermaFrame:SetVisible( true ) end },
	Tree2 = { "I'm explorin', sorry to disturb", function() ChatFrame:SetVisible( false ) end }
}

local Weapons = {
	Shotgun = {"models/weapons/w_shot_m3super90.mdl", "$1,750", "Shotgun", "Shoots 6 bullets at once", 1750, "weapon_pumpshotgun" },
	Mac = {"models/weapons/w_smg_mac10.mdl", "$1,500", "Mac10", "A fast but weak weapon", 1500, "weapon_mac10" },
	Ak = {"models/weapons/w_rif_ak47.mdl", "$3,000", "AK47", "A strong but high recoiled weapon", 3000, "weapon_ak47" },
	Deagle = {"models/weapons/w_pist_deagle.mdl", "$800", "Deagle", "A strong pistol", 800, "weapon_deagle" },
	Fiveseven = {"models/weapons/w_pist_fiveseven.mdl", "$750", "Fiveseven", "A fast but weak weapon", 750, "weapon_fiveseven" },
	Glock = {"models/weapons/w_pist_glock18.mdl", "$700", "Glock", "A weak, cheap but fast weapon", 700, "weapon_glock" },
	M16 = {"models/weapons/w_rif_m4a1.mdl", "$2,500", "M16", "A accurate but slow weapon", 2500, "weapon_m4" },
	MP5 = {"models/weapons/w_smg_mp5.mdl", "$2,000", "MP5", "A fast shooting but weak weapon", 2000, "weapon_mp5" },
	Para = {"models/weapons/w_mach_m249para.mdl", "$4,500", "Para", "A strong weapon with a bunch of ammo", 4500, "weapon_para" },
	TMP = {"models/weapons/w_smg_tmp.mdl", "$1,750", "TMP", "A silented sweat weapon", 1750, "weapon_tmp" }
	
}
	
function NPCMenu()	
	
surface.CreateFont( "coolvectica", 20, 400, true, false, "CV20" )
	
ChatFrame = vgui.Create( "DFrame" )
ChatFrame:SetSize( 600, 150 )
ChatFrame:SetPos( ScrW() / 2 - ChatFrame:GetWide() / 2, ScrH() - ChatFrame:GetTall() - 10 )
ChatFrame:SetTitle( "Chat Menu" )
ChatFrame:SetVisible( true )
ChatFrame:SetDraggable( false )
ChatFrame:ShowCloseButton( false )
ChatFrame:MakePopup()

local ChatTextList = vgui.Create( "DPanelList", ChatFrame )
ChatTextList:SetPos( 10, 32 )
ChatTextList:SetSize( ChatFrame:GetWide() - 20, ChatFrame:GetTall() - 107 )
ChatTextList:SetSpacing( 3 )
ChatTextList:EnableHorizontal( false )
ChatTextList:EnableVerticalScrollbar( true )

local ChatText = vgui.Create( "DLabel", ChatTextList )
ChatText:SetText( "Can I help you at all?" )
ChatText:SizeToContents()
ChatText:SetWrap( true )
ChatText:Center()

local ChatButtonList = vgui.Create( "DPanelList", ChatFrame )
ChatButtonList:SetPos( 10, 82 )
ChatButtonList:SetSize( ChatFrame:GetWide() - 20, ChatFrame:GetTall() - 92 )
ChatButtonList:SetSpacing( 0 )
ChatButtonList:EnableHorizontal( false )
ChatButtonList:EnableVerticalScrollbar( true )

	 for k,v in pairs( Chat ) do 

		local DermaButton = vgui.Create( "DButton", ChatButtonList )
		DermaButton:SetSize( ChatButtonList:GetWide() - 20, 20 )
		DermaButton:SetPos( 10, 3 )
		DermaButton:SetText( v[1] )
		DermaButton.DoClick = v[2]
		ChatButtonList:AddItem( DermaButton )
	end
	
	//frame
DermaFrame = vgui.Create( "DFrame" )
DermaFrame:SetSize( ScrW() - 400, ScrH() - 300 )
DermaFrame:SetTitle( "Drug Dealer" )
DermaFrame:SetVisible( false )
DermaFrame:SetDraggable ( false )
DermaFrame:ShowCloseButton( true )
DermaFrame:Center()
DermaFrame:MakePopup()


	//DermaList
local DermaList = vgui.Create( "DPanelList", DermaFrame )
DermaList:SetPos( 10, 32 )
DermaList:SetSize( DermaFrame:GetWide() - 20, DermaFrame:GetTall() - 42 )
DermaList:SetSpacing( 1 )
DermaList:EnableHorizontal( false )
DermaList:EnableVerticalScrollbar( true )

	
	for k, v in pairs(Weapons) do 
		
		local DermaPanel = vgui.Create( "DPanel", DermaList )
		DermaPanel:SetSize( DermaList:GetWide(), 100 )
		DermaPanel.Paint = function()
			draw.RoundedBox( 8, 10, 10, DermaPanel:GetWide() - 20, DermaPanel:GetTall() - 10, Color( 100, 95, 95, 255 ))
		end
		
		local SpawnIcon = vgui.Create( "SpawnIcon", DermaPanel)
		SpawnIcon:SetPos( 20, 20 )
		SpawnIcon:SetToolTip( false )
		SpawnIcon:SetModel( v[1] )
		
		local DermaLabel = vgui.Create( "DLabel", DermaPanel )
		DermaLabel:SetPos( 100, 20 )
		DermaLabel:SetText( v[2] )
		DermaLabel:SetFont( "CV20" )
		DermaLabel:SizeToContents()
		DermaLabel:SetColor( Color( 255, 255, 255, 255) )
		
		local DermaLabel2 = vgui.Create( "DLabel", DermaPanel )
		DermaLabel2:SetPos( DermaPanel:GetWide() / 2 - 40, 20 )
		DermaLabel2:SetText( v[3] )
		DermaLabel2:SetFont( "CV20" )
		DermaLabel2:SizeToContents()
		DermaLabel2:SetColor( Color( 255, 255, 255, 255) )
		
		local DermaLabel3 = vgui.Create( "DLabel", DermaPanel )
		DermaLabel3:SetPos( 100, 40 )
		DermaLabel3:SetText( v[4] )
		DermaLabel3:SizeToContents()
		DermaLabel3:SetColor( Color( 255, 255, 255, 255) )
		
		local DermaButton = vgui.Create( "DButton", DermaPanel )
		DermaButton:SetSize( 100, 30 )
		DermaButton:SetPos( DermaPanel:GetWide() - 140, 60 )
		DermaButton:SetText( "Buy!" )
		DermaButton.DoClick = function( Weapons )
			LocalPlayer():ConCommand( "_weapongive_ "..v[6].." "..v[5] )
		end
		DermaList:AddItem( DermaPanel )
	end

end

function ENT:Draw()
	self.Entity:DrawModel()
	
	local Pos = self:GetPos()
	local Ang = self:GetAngles()
	
	surface.SetFont("HUDNumber5")
	local TextWidth = surface.GetTextSize("Gundealer")

	Ang:RotateAroundAxis(Ang:Up(), 90)
	
	cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
		draw.WordBox(2, -TextWidth*0.5, -30, "Gundealer", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
	cam.End3D2D()
end

usermessage.Hook("GunDealerUsed", NPCMenu)